<script type="text/javascript">
function cariRadiologi(){
	var id_ppk=$('#nama_ppk').val();
	popupCari('module/mod_klaim/js/popup_radiologi.php?id_ppk='+id_ppk);
}

function hapusRadiologi(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
		kalkulasi_tindakan();
	}
}

function kalkulasi_radiologi(){
	//alert('coba');
	var jumlah_invoice=0;
	var jumlah_invoice_awal=0;
	jumlah_invoice=hitung_total_invoice_radiologi();
	jumlah_invoice_awal=hitung_total_invoice_radiologi_awal();
	var selisih_radiologi=jumlah_invoice_awal-jumlah_invoice;
	//alert('jumlah invoice '+jumlah_invoice);
	$('#total_radiologi').val(jumlah_invoice);
	$('#target_total_radiologi').html(number_format(jumlah_invoice, 0, ',','.'));
	$('#total_radiologi_awal').val(jumlah_invoice_awal);
	$('#target_total_radiologi_awal').html(number_format(jumlah_invoice_awal, 0, ',','.'));
	$('#target_selisih_radiologi').html(number_format(selisih_radiologi, 0, ',','.'));
	$('#selisih_radiologi').val(selisih_radiologi);
	hitung_semua_klaim();
}
function hitung_total_invoice_radiologi_awal(){
	//alert('kocor');
		var frm=document.forms['form_klaim'];
		var harga_brg=frm.elements['harga_radiologi_awal[]'];
		if(harga_brg==undefined){
			return 0;
		}
		//alert(harga_brg+' dan '+jml_pesanan);
		n=harga_brg.length;
		var total=0;
		var sub_total=0
		if(n>1){
			for(var i=0;i<n;i++){
				sub_total=parseFloat(harga_brg[i].value);
				total+=sub_total;
			}
		}else{
			sub_total=parseFloat(harga_brg.value);
			total+=sub_total;
		}
		//alert(total);
		return total;
}
function hitung_total_invoice_radiologi(){
	//alert('kocor');
		var frm=document.forms['form_klaim'];
		var harga_brg=frm.elements['harga_radiologi[]'];
		if(harga_brg==undefined){
			return 0;
		}
		//alert(harga_brg+' dan '+jml_pesanan);
		n=harga_brg.length;
		var total=0;
		var sub_total=0
		if(n>1){
			for(var i=0;i<n;i++){
				sub_total=parseFloat(harga_brg[i].value);
				total+=sub_total;
			}
		}else{
			sub_total=parseFloat(harga_brg.value);
			total+=sub_total;
		}
		//alert(total);
		return total;
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><table class="tabel" width="90%">
           <tr>
             <th scope="col">Nama Radiologi </th>
             <th scope="col">Harga Ditanggung </th>
             <th scope="col">Harga Diminta </th>
             <th scope="col">&nbsp;</th>
           </tr>
			<tbody id="tbody_list_radiologi">
			<?php
			$sql_tindakan="select a.id_radiologi, b.nama_radiologi,c.tarif,a.tarif_ditanggung from 
						klaim_radiologi a inner join master_radiologi b on a.id_radiologi=b.id_radiologi 
						inner JOIN tarif_radiologi c ON b.id_radiologi=c.id_radiologi
					 where a.id_klaim='".$id_klaim."'";
				//echo $sql_obat;
			$qry_tindakan=mysql_query($sql_tindakan);
			$num_radiologi=mysql_num_rows($qry_tindakan);
			//echo 'num hasil '.$num_obat;
			$no=1;
			$total_tarif=0;
			$total_tarif_tanggung=0;
			if(!empty($id_klaim)&& $num_radiologi>0){
				while($hasil_tindakan=mysql_fetch_array($qry_tindakan)){
			?>
			<tr>
			<td><?php echo $hasil_tindakan['nama_radiologi']; ?><input type="hidden" name="id_radiologi[]"  value="<?php echo $hasil_tindakan['id_radiologi']; ?>"></td>
			<td><?php echo number_format($hasil_tindakan['tarif'],0,",","."); ?></td>
			<td><input type="text" size="10" name="harga_radiologi[]" id="harga_radiologi_<?php echo $no;?>"  value="<?php echo $hasil_tindakan['tarif_ditanggung']; ?>">
			<input type="hidden" size="5" name="harga_radiologi_awal[]" id="harga_radiologi_awal_<?php echo $no;?>" value="<?php echo $hasil_tindakan['tarif']; ?>"></td>
			<td><a href="javascript:void(null)" title="Hapus" onclick="hapusRadiologi(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a></td>
			</tr>
			<?php 
				$total_tarif+=$hasil_tindakan['tarif'];
				$total_tarif_tanggung+=$hasil_tindakan['tarif_ditanggung'];
				$no++;
			}
			$selisih=$total_tarif-$total_tarif_tanggung;
				$count_radiologi=$num_radiologi+1;
			}else{
				$count_radiologi=1;
			}
			?>
		   </tbody>
</table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
       <td><a href="javascript:void(0)" title="Tambah" onclick="cariRadiologi()"><img src="asset/images/button-add.gif" alt="Tambah" border=0 /></a></td>
       <td><input type="hidden" id="count_radiologi" value="<?php echo $count_radiologi;?>" /></td>
  </tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="0">
<tr>
    <td>Sub Total </td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_total_radiologi_awal" style="font-weight:bold;"><?php echo isset($total_tarif)?number_format($total_tarif,0,",","."):0;?></div>
	<input type="hidden" id="total_radiologi_awal" value="<?php echo isset($total_tarif)?$total_tarif:0;?>" />	</td>
  </tr>
  <tr>
    <td>Sub Total Ditanggung</td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_total_radiologi" style="font-weight:bold;"><?php echo isset($total_tarif_tanggung)?number_format($total_tarif_tanggung,0,",","."):0;?></div>
	<input type="hidden" id="total_radiologi" value="<?php echo isset($total_tarif_tanggung)?$total_tarif_tanggung:0;?>" /></td>
  </tr>
  <tr>
    <td>Selisih</td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td><div id="target_selisih_radiologi" style="font-weight:bold;"><?php echo isset($selisih)?number_format($selisih,0,",","."):0;?></div>
	<input type="hidden" id="selisih_radiologi" value="<?php echo isset($selisih)?$selisih:0;?>" />
	</td>
  </tr>
</table>


